package org.pathlet.core.config.convert;

import java.util.Collection;

/**
 * BeanResource中的properties中的值对象的描述信息。
 * 它代表每一个配置项的值的描述信息，包括值的类型，值的类型，值的子节点等。
 */
public class ValueNode {

	/**
	 * 此为"值"的配置点的值。
	 * 如:配置的是 @InstanceIn("/path/to/instance")，则此值为"/path/to/instance"
	 */
	private Object value;

	private Object key; //If this valueNode is Map entry. this property is the Map's key

	/**
	 * 值类型
	 */
	private ValueNodeType type;

	/**
	 * 值的类型(Class)
	 */
	private Class<?> valueType;

	/**
	 * 如果是集合类型，子节点
	 */
	private Collection<ValueNode> children;

	public ValueNode() {

	}

	public ValueNode(ValueNodeType type, Object value) {
		this.type = type;
		this.value = value;
		if(value != null) {
			this.valueType = value.getClass();
		}
	}

	public Object getKey() {
		return key;
	}

	public void setKey(Object key) {
		this.key = key;
	}

	public Class<?> getValueType() {
		return valueType;
	}

	public void setValueType(Class<?> valueType) {
		this.valueType = valueType;
	}

	public Object getValue() {
		return value;
	}

	public void setValue(Object value) {
		this.value = value;
		if(value != null) {
			this.valueType = value.getClass();
		}
	}

	public ValueNodeType getType() {
		return type;
	}

	public void setType(ValueNodeType type) {
		this.type = type;
	}

	public Collection<ValueNode> getChildren() {
		return children;
	}

	public void setChildren(Collection<ValueNode> children) {
		this.children = children;
	}

	public enum ValueNodeType {
		COLLECTION,
		MAP,

		STRING,
		BOOLEAN,
		INTEGER,
		LONG,
		FLOAT,
		DOUBLE,

		PATH,
		MATCH_PATTERN,
		INSTANCE,
		INSTANCE_TYPE,
		RESOURCE,
		SPACE,
		CONTAINER
	}
}
